#include "StdAfx.h"
#include "MonitorClient.h"
#include "MonitorWorktable.h"
#include "BaseDialog.h"

CMonitorWorktable::CMonitorWorktable(DWORD dwID)
	: m_dwID(dwID)
	, m_pMultiDisplayDlg(NULL)
	, m_pMainView(NULL)
{
}

CMonitorWorktable::~CMonitorWorktable(void)
{
}

void CMonitorWorktable::AddWindow(CWnd* pWnd, BOOL bShow)
{
	m_WndInfoArray.push_back(WND_INFO(pWnd, bShow));

	if(pWnd->IsKindOf(RUNTIME_CLASS(CBaseDialog)))
	{
		static_cast<CBaseDialog*>(pWnd)->SetWorktable(this);
	}
}

void CMonitorWorktable::AddWindow(CWnd *pWnd)
{
	BOOL bShow = FALSE;

	if(pWnd->GetStyle() & WS_VISIBLE)
		bShow = TRUE;

	AddWindow(pWnd, bShow);
}

void CMonitorWorktable::SetActive(BOOL bActive)
{
	BOOL bShow;
	for(size_t i = 0; i < m_WndInfoArray.size(); ++i)
	{
		if(bActive)
		{
			if(m_WndInfoArray[i].m_bShow)
				m_WndInfoArray[i].m_pWnd->ShowWindow(SW_SHOW);
		}
		else
		{
			if(m_WndInfoArray[i].m_pWnd->GetStyle() & WS_VISIBLE)
				bShow = TRUE;
			else
				bShow = FALSE;

			m_WndInfoArray[i].m_bShow = bShow;
			if(bShow)
				m_WndInfoArray[i].m_pWnd->ShowWindow(SW_HIDE);
		}
	}
}

void CMonitorWorktable::SendToolbarCommand(UINT nCommand)
{
	if(m_pMainView)
		m_pMainView->SendMessage(WM_COMMAND, MAKEWPARAM(nCommand, 0), 0);
}
